package com.example.demo.controller;


import com.example.demo.model.Data;
import com.example.demo.service.DataService;
import com.example.demo.tool.ResponseMessage;
import com.example.demo.tool.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * 编写者：施皓
 * 编写时间：2019.5.28
 */
@RestController(value = "/Data")
public class DataController {
    @Autowired
    private DataService dataService;

    @RequestMapping(value = "/getData")
    public String getStr(String str){
        return "你输入的名字叫" + str;

    }
    @CrossOrigin
    @RequestMapping(value = "/getDataOne")
    public Data getOne(Integer did){
        return dataService.DataKey(did);
    }

    @CrossOrigin//解决跨越问题
    @RequestMapping(value = "getsex")
    public List<Data> getsex(){
        System.out.println("调用角色全部类型的接口");
        List<Data> listData = dataService.getsex();
        return listData;
    }

    @CrossOrigin
    @RequestMapping(value = "getAllData")
    public ResponseMessage getAllData(){
        List<Data> listData = dataService.getAllData();
        System.out.println("调用角色全部信息的方法");
        Map<String,List> map = new HashMap<>();
        map.put("list",dataService.getAllData());
        return Result.success("200",map);
    }
    @CrossOrigin
    @RequestMapping(value = "/delData",method =  RequestMethod.GET)
    public int delData(Integer did){
        return dataService.delData(did);
    }

    @CrossOrigin
    @RequestMapping(value = "/insertData",method = RequestMethod.PUT)
    public int insertData(@RequestBody Data datamodel){
        //判断传入数据是否为空
        if (datamodel!=null){

        }else {

        }
        return dataService.insertData(datamodel);
    }
    @CrossOrigin
    @RequestMapping(value = "/updateData",method = RequestMethod.PUT)
    public  int updateData(@RequestBody Data datamodel){
        if (datamodel!=null){

        }else {

            System.out.println("请输入数据");
        }
        return dataService.updateData(datamodel);
    }
}
